﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Report_Receipt.ascx.cs" Inherits="ERP.Modules.Report_Receipt" %>
<%-------------------------------%>
<ext:Hidden ID="FormatTypeReportReceipt" runat="server" />
<%--------------GridReportReceipt-----------------%>
<ext:Panel ID="PanelReportReceipt" runat="server" Layout="Fit" Border="False">
    <Content>
        <ext:GridPanel
            ID="grReportReceipt"
            runat="server"
            Cls="grid-double"
            EnableColumnMove="true"
            Border="False">
            <Store>
                <ext:Store
                    ID="StoreReportReceipt"
                    runat="server"
                    OnReadData="StoreReportReceipt_RefreshData"
                    PageSize="20">
                    <Model>
                        <ext:Model runat="server" IDProperty="ReportReceipt_ID" GroupField="ReportReceipt_Code">
                            <Fields>
                                <ext:ModelField Name="Amount_Total" Type="Float" />
                                <ext:ModelField Name="Note" Type="String" />
                                <ext:ModelField Name="Lock" Type="Boolean" />
                                <ext:ModelField Name="ReportReceipt_Code" Type="String" />
                                <ext:ModelField Name="DateCreate" Type="Date" />
                                <ext:ModelField Name="Receipt_ID" Type="Int" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:RowNumbererColumn runat="server" Width="30" Align="Center" />
                    <ext:Column runat="server" Text="Mã báo cáo" Width="115" DataIndex="ReportReceipt_Code"/>
                    <ext:DateColumn runat="server" Text="Ngày lập" Width="160" DataIndex="DateCreate" Format="dd-MM-yyyy" Align="Center"/>
                    <ext:NumberColumn runat="server" Text="Tổng tiền" Width="90" DataIndex="Amount_Total" Format="0,00" Align="Center" />
                    <ext:CheckColumn runat="server" Text="Trạng thái" Width="157" DataIndex="Lock" Align="Center"/>
                    <ext:Column runat="server" Text="Ghi chú" Width="122" DataIndex="Note" Flex="1">
                        <Renderer Fn="gridNull" />
                    </ext:Column>
                </Columns>
            </ColumnModel>
            <Features>
                <ext:Grouping
                    runat="server" 
                    HideGroupedHeader="true"
                    GroupByText="Xem theo phân nhóm"
                    ShowGroupsText="Phân nhóm"
                    GroupHeaderTplString="{name} ({rows.length} danh mục con {[values.rows.length > 1 ? '' : '']})"
                    StartCollapsed="True" />
            </Features>
            <DirectEvents>
                <ItemDblClick OnEvent="ReportReceiptDblClick">
                    <ExtraParams>
                        <ext:Parameter Name="ReportReceipt_ID" Value="record.data.ReportReceipt_ID" Mode="Raw" />
                    </ExtraParams>
                    <EventMask ShowMask="true" Msg="Đang tải..." />
                </ItemDblClick>
            </DirectEvents>
            <SelectionModel>
                <ext:CheckboxSelectionModel runat="server" Mode="Multi">
                   <Listeners>
                       <SelectionChange Handler="
                            if (selected.length == 0) {
                                #{btnEdit}.disable();
                                #{btnDel}.disable();
                                #{btnExport}.disable();
                            } else {
                                #{btnEdit}.enable();
                                #{btnDel}.enable();
                                #{btnExport}.enable();
                            }" />
                   </Listeners>
                </ext:CheckboxSelectionModel>
            </SelectionModel>
            <View>
                <ext:GridView runat="server" StripeRows="true" />
            </View>
            <DockedItems>
                <ext:Toolbar runat="server" Dock="Top">
                    <Items>
                        <ext:Button ID="btnAddNew" runat="server" Text="Thêm mới" Icon="ApplicationAdd">
                            <DirectEvents>
                                <Click OnEvent="btnAddNew_Click">
                                    <EventMask ShowMask="true" Msg="Đang tải..." />
                                </Click>
                            </DirectEvents> 
                        </ext:Button>
                        <ext:ToolbarSeparator />
                        <ext:Button ID="btnEdit" runat="server" Text="Sửa" Icon="ApplicationEdit">
                            <DirectEvents>
                                <Click OnEvent="btnEdit_Click">
                                    <EventMask ShowMask="true" Msg="Đang tải..." />
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                        <ext:ToolbarSeparator />
                        <ext:Button ID="btnDel" runat="server" Text="Xoá" Icon="ApplicationDelete">
                            <DirectEvents>
                                <Click OnEvent="btnDel_Click">
                                    <EventMask ShowMask="true" Msg="Đang tải..." />
                                    <ExtraParams>
                                        <ext:Parameter Name="name" Value="btnDel"></ext:Parameter>
                                    </ExtraParams>
                                    <Confirmation ConfirmRequest="true"
                                        Title="Thông Báo" Message="Bạn có muốn xoá mẫu tin này không ?">
                                    </Confirmation>
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                        <ext:ToolbarSeparator />
                        <ext:Button ID="btnExport" runat="server" Text="Xuất tập tin" Icon="Printer">
                            <Menu>
                                <ext:Menu ID="MenuMain" runat="server">
                                    <Items>
                                        <ext:MenuItem ID="MenuItemExportExcel" runat="server" Text="Excel" Icon="PageExcel">
                                           <DirectEvents>
                                               <Click OnEvent="MenuItemExportExcel_Click" IsUpload="true">
                                                    <ExtraParams>
                                                        <ext:Parameter Name="grReportReceipt" Value="Ext.encode(#{grReportReceipt}.getRowsValues({selectedOnly : true}))" Mode="Raw" />
                                                    </ExtraParams>
                                               </Click>
                                           </DirectEvents>
                                        </ext:MenuItem>
                                    </Items>
                                </ext:Menu>
                            </Menu>
                        </ext:Button>
                        <ext:ToolbarSeparator />
                        <ext:DateField ID="txtDateBeginFillter" EmptyText="Từ ngày" runat="server" MarginSpec="0 8 0 0"/>
                        <ext:DateField ID="txtDateEndFillter" EmptyText="Đến ngày" runat="server" MarginSpec="0 5 0 0"/>
                        <ext:Button ID="btnFillter" runat="server" Text="Lọc" Icon="ApplicationGo" ToolTip="Chọn lọc theo ngày đặt hàng">
                            <DirectEvents>
                                <Click OnEvent="btnFillter_Click">
                                    <EventMask ShowMask="true" Msg="Đang tải..." />
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
                <ext:Toolbar runat="server" Dock="Bottom" AnchorHorizontal="100%">
                    <Items>
                        <ext:TriggerField ID="txtSearch" runat="server" Width="200" EnableKeyEvents="true" MarginSpec="0 8 0 0">
                            <Triggers>
                                <ext:FieldTrigger Icon="Search" />
                            </Triggers>
                            <DirectEvents>
                                <TriggerClick OnEvent="Search_Event">
                                     <EventMask ShowMask="true" Msg="Đang tải..." />
                                </TriggerClick>
                                <SpecialKey OnEvent="Search_Event" Before="return e.getKey() == Ext.EventObject.ENTER;">
                                     <EventMask ShowMask="true" Msg="Đang tải..." />
                                </SpecialKey>
                            </DirectEvents>
                        </ext:TriggerField>
                        <ext:PagingToolbar runat="server" StoreID="StoreReportReceipt" BeforePageText="Trang" AfterPageText="của {0}" LastText="Cuối" NextText="Kế tiếp" PrevText="Trở lại" FirstText="Đầu" RefreshText="Làm tươi" DisplayInfo="true" DisplayMsg="Trang {0} - {1} của {2}" />
                    </Items>
                </ext:Toolbar>
            </DockedItems>
        </ext:GridPanel>
    </Content>
</ext:Panel>
<ext:Panel runat="server">
    <Content>
        <%-----------------WindowsReportReceipt-----------------%>
        <ext:Window ID="WindowsReportReceipt" runat="server"
            Title="Chốt sổ"
            Width="975"
            Height="534"
            Hidden="true"
            Region="Center"
            Modal="true"
            HideMode="Display"
            Border="false"
            Padding="5"
            DefaultButton="btnSavePopUp"
            Resizable="False">
            <Items>
                <ext:Toolbar runat="server">
                    <Items>
                        <ext:Button runat="server" Text="Lưu lại" Icon="Disk" ID="btnSavePopUp">
                            <DirectEvents>
                                <Click OnEvent="btnSavePopUp_Click" Before="return #{FormPanelReportReceipt}.isValid();">
                                    <EventMask ShowMask="true" Msg="Đang tải..." />
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                        <ext:ToolbarSeparator />
                        <ext:Button runat="server" Text="Chốt sổ" Icon="Add" ID="btnAddMaterial" MarginSpec="0 8 0 0">
                            <DirectEvents>
                                <Click OnEvent="btnAddMaterial_Click">
                                    <EventMask ShowMask="true" Msg="Đang tải..." />
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                        <ext:ToolbarSeparator />
                        <ext:Button runat="server" Text="Mở khoá chứng từ" Icon="Cancel" ID="btnDelMaterial" MarginSpec="0 8 0 0">
                            <DirectEvents>
                                <Click OnEvent="btnDelMaterial_Click">
                                    <EventMask ShowMask="true" Msg="Đang tải..." />
                                    <ExtraParams>
                                        <ext:Parameter Name="name" Value="btnDel"></ext:Parameter>
                                    </ExtraParams>
                                    <Confirmation ConfirmRequest="true"
                                        Title="Thông Báo" Message="Bạn có muốn mở khoá chứng từ này không ?">
                                    </Confirmation>
                                    <ExtraParams>
                                        <ext:Parameter Name="grReportReceipt_Detail" Value="Ext.encode(#{grReportReceipt_Detail}.getRowsValues({selectedOnly : true}))" Mode="Raw" />
                                    </ExtraParams>
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                        <ext:ToolbarSeparator />
                        <ext:Button runat="server" Text="Huỷ bỏ" Icon="Decline" ID="btnCancelPopUp">
                            <DirectEvents>
                                <Click OnEvent="btnCancelPopUp_Click">
                                    <EventMask ShowMask="true" Msg="Đang tải..." />
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                        <ext:TextField ID="txtReportReceipt_ID" runat="server" FieldLabel="ID" LabelAlign="Right" Hidden="true" />
                    </Items>
                </ext:Toolbar>
                <ext:Panel
                runat="server" 
                Layout="ColumnLayout">
                <Items>
                    <ext:Panel
                        runat="server" 
                        Width="218"
                        Frame="True"
                        MarginSpec="0 5 0 0"
                        Height="520">
                        <Items>
                            <ext:FormPanel ID="FormPanelReportReceipt" runat="server"
                                AutoHeight="true"
                                BodyPadding="4"
                                Frame="true"
                                DefaultAnchor="100%">
                                <Items>
                                    <ext:Label runat="server" LabelWidth="83" LabelAlign="Top" Text="Mã báo cáo" />
                                    <ext:FieldContainer
                                         runat="server"
                                         AnchorHorizontal="100%"
                                         Layout="HBoxLayout">
                                         <Items>
                                            <ext:TextField ID="txtReportReceiptCode" runat="server" AllowBlank="False" Width="165" Margins="8 3 0 0" />
                                            <ext:Button runat="server" Text="" Icon="Reload" ID="btnRefreshReportReceiptCode" ToolTip="Click vào để tải lại mã" Margins="8 3 0 0">
                                                <DirectEvents>
                                                    <Click OnEvent="btnRefreshReportReceiptCode_Click">
                                                        <EventMask ShowMask="true" Msg="Đang tải..." />
                                                    </Click>
                                                </DirectEvents>
                                            </ext:Button>
                                         </Items>
                                     </ext:FieldContainer>
                                    <ext:Label runat="server" LabelWidth="83" LabelAlign="Top" Text="Ngày lập HĐ" Margins="8 3 0 0" />
                                    <ext:DateField ID="txtDateBegin" runat="server" AllowBlank="False" Width="250" MarginSpec="8 3 5 0" />
                                    <ext:Label runat="server" LabelWidth="83" LabelAlign="Top" Text="Tổng tiền" MarginSpec="8 3 8 0" />
                                    <ext:TextField ID="txtAmount_Total" FieldStyle="text-align: right;" ReadOnly="True" AllowBlank="False" runat="server" Width="250" MarginSpec="8 3 8 0" />
                                    <ext:Label runat="server" LabelWidth="83" LabelAlign="Top" Text="Ghi chú" MarginSpec="0 3 8 0" />
                                    <ext:TextArea ID="txtNote" runat="server" AnchorHorizontal="100%" Height="30" MarginSpec="5 0 0 0"/>
                                    <ext:Label runat="server" LabelWidth="83" LabelAlign="Top" Text="Lý do mở khoá" MarginSpec="0 3 8 0" />
                                    <ext:TextArea ID="txtReason" runat="server" AnchorHorizontal="100%" Height="30" MarginSpec="5 0 0 0"/>
                                </Items>
                            </ext:FormPanel>
                        </Items>
                    </ext:Panel>
                    <ext:Panel
                        runat="server" 
                        Width="736"
                        Layout="Fit" 
                        Border="False"
                        Height="410">
                        <Items>
                            <ext:GridPanel
                                ID="grReportReceipt_Detail"
                                Cls="grid-double"
                                runat="server"
                                EnableColumnMove="true"
                                AutoWidth="true"
                                AutoScroll="true"
                                Layout="Fit"
                                Height="190">
                                <Store>
                                    <ext:Store
                                        ID="StoreReportReceipt_Detail"
                                        runat="server"
                                        OnReadData="StoreReportReceipt_Detail_RefreshData">
                                        <Model>
                                            <ext:Model runat="server" IDProperty="ReportDetail_Id">
                                                <Fields>
                                                    <ext:ModelField Name="ID_Sell" Type="Int" />
                                                    <ext:ModelField Name="Receipt_ID" Type="Float" />
                                                    <ext:ModelField Name="ReportReceipt_ID" Type="Int" />
                                                    <ext:ModelField Name="ReportReceipt_Code" Type="String" />
                                                    <ext:ModelField Name="ReceiptCode" Type="String" />
                                                    <ext:ModelField Name="ReceiptDate" Type="Date" />
                                                    <ext:ModelField Name="VoucherAmount" Type="Float" />
                                                    <ext:ModelField Name="Amount" Type="Float" />
                                                </Fields>
                                            </ext:Model>
                                        </Model>
                                    </ext:Store>
                                </Store>
                                <ColumnModel runat="server">
                                    <Columns>
                                        <ext:RowNumbererColumn Text="STT" runat="server" Width="30" Align="Center" />
                                        <ext:Column runat="server" Text="Mã báo cáo" Width="100" DataIndex="ReportReceipt_Code" />
                                        <ext:Column runat="server" Text="Mã phiếu thu" Width="100" DataIndex="ReceiptCode" />
                                        <ext:DateColumn runat="server" Text="Ngày lập phiếu" Width="150" DataIndex="ReceiptDate" Format="dd-MM-yyyy" Align="Center" />
                                        <ext:NumberColumn runat="server" Text="Giá tiền theo chứng từ" Hidden="True" Width="200" DataIndex="VoucherAmount" Format="0,00" />
                                        <ext:NumberColumn runat="server" Text="Số tiền thanh toán" Flex="1" DataIndex="Amount" Format="0,00" Align="Center" /> 
                                    </Columns>
                                </ColumnModel>
                                <DirectEvents>
                                    <ItemDblClick OnEvent="ReportReceiptDetailDblClick">
                                        <ExtraParams>
                                            <ext:Parameter Name="ReportDetail_Id" Value="record.data.ReportDetail_Id" Mode="Raw" />
                                        </ExtraParams>
                                        <EventMask ShowMask="true" Msg="Đang tải..." />
                                    </ItemDblClick>
                                </DirectEvents>
                                <SelectionModel>
                                    <ext:CheckboxSelectionModel runat="server" Mode="Multi"/>
                                </SelectionModel>
                                <DockedItems>
                                    <ext:Toolbar runat="server" Dock="Bottom" AnchorHorizontal="100%">
                                        <Items>
                                            <ext:PagingToolbar runat="server" StoreID="StoreReportReceipt_Detail" EmptyMsg="Không có dữ liệu" BeforePageText="Trang" AfterPageText="của {0}" LastText="Cuối" NextText="Kế tiếp" PrevText="Trở lại" FirstText="Đầu" RefreshText="Làm tươi" DisplayInfo="true" DisplayMsg="Trang {0} - {1} của {2}" />
                                        </Items>
                                    </ext:Toolbar>
                                </DockedItems>
                            </ext:GridPanel>
                        </Items>
                    </ext:Panel>
                    <ext:Panel
                        runat="server" 
                        Width="736"
                        MarginSpec="5 0 0 0"
                        Border="True"
                        Frame="True"
                        Height="56">
                        <Items>
                            <ext:FieldContainer
                                runat="server"
                                AnchorHorizontal="100%">
                                <Items>
                                    <ext:Label runat="server" Text="Tổng tiền theo chứng từ:" MarginSpec="0 8 8 0"></ext:Label>
                                    <ext:Label ID="lbPriVATOrderReportReceipt" Cls="x-label-right-cost" runat="server" Text="0" AnchorHorizontal="100%"></ext:Label>
                                </Items>
                            </ext:FieldContainer>
                            <ext:FieldContainer
                            runat="server"
                            AnchorHorizontal="100%">
                            <Items>
                                 <ext:Label runat="server" Text="Tổng tiền thanh toán:" MarginSpec="0 8 8 0"></ext:Label>
                                 <ext:Label ID="lbTotalCostOrderReportReceipt" Cls="x-label-right-cost" runat="server" Text="0" AnchorHorizontal="100%"></ext:Label>
                            </Items>
                        </ext:FieldContainer>
                        </Items>
                    </ext:Panel>
                </Items>
                </ext:Panel>
            </Items>
        </ext:Window>
        <%-----------WindowsReceipt---------------------%>
        <ext:Window ID="WindowReceipt" runat="server"
            Title="Thông phiếu thu"
            DefaultAnchor="100%"
            Width="829"
            Height="400"
            Hidden="true"
            AutoScroll="false"
            Maximizable="False"
            Minimizable="False"
            AutoDataBind="true"
            Region="Center"
            Resizable="False"
            Modal="true"
            Layout="Fit"
            HideMode="Offsets"
            Constrain="True">
            <Items>
                <ext:GridPanel
                    ID="grReceipt"
                    Border="True"
                    runat="server"
                    AutoWidth="true"
                    AutoScroll="true"
                    Cls="gird"
                    EnableColumnMove="true">
                    <Store>
                        <ext:Store
                            ID="StoreReportReceiptOrder"
                            runat="server"
                            OnReadData="StoreReportReceiptOrder_RefreshData"
                            PageSize="14">
                            <Model>
                                <ext:Model runat="server" IDProperty="ID">
                                    <Fields>
                                        <ext:ModelField Name="ReceiptCode" Type="String" />
                                        <ext:ModelField Name="Sell_Code" Type="String" />
                                        <ext:ModelField Name="Order_Sell_Code" Type="String" />
                                        <ext:ModelField Name="Customer_Alias" Type="String" />
                                        <ext:ModelField Name="Customer_Name" Type="String" />
                                        <ext:ModelField Name="ReceiptDate" Type="Date" />
                                        <ext:ModelField Name="Customer_Type_Name" Type="String" />
                                    </Fields>
                                </ext:Model>
                            </Model>
                        </ext:Store>
                    </Store>
                    <ColumnModel runat="server">
                        <Columns>
                            <ext:RowNumbererColumn runat="server" Width="30" Align="Center" />
                            <ext:Column runat="server" Text="Mã phiếu thu" Width="100" DataIndex="ReceiptCode" Align="Left"/>
                            <ext:DateColumn runat="server" Text="Ngày lập" Width="160" DataIndex="ReceiptDate" Format="dd-MM-yyyy" Align="Center" Flex="1"/>
                            <ext:Column runat="server" Text="HĐ bán hàng" Width="100" DataIndex="Order_Sell_Code" Align="Left"/>
                            <ext:Column runat="server" Text="HĐ đặt hàng" Width="100" DataIndex="Sell_Code" Align="Left"/>
                            <ext:Column runat="server" Text="Mã khách hàng" Width="100" DataIndex="Customer_Alias" Align="Left"/>
                            <ext:Column runat="server" Text="Tên khách hàng" Width="160" DataIndex="Customer_Name" Align="Left"/>
                            <ext:Column runat="server" Text="Loại khách hàng" Flex="1" DataIndex="Customer_Type_Name" Align="Left"/>
                        </Columns>
                    </ColumnModel>
                    <SelectionModel>
                        <ext:CheckboxSelectionModel runat="server" Mode="Multi">
                           <Listeners>
                               <SelectionChange Handler="
                                    if (selected.length == 0) {
                                        #{btnChooseReceipt}.disable();
                                    } else {
                                        #{btnChooseReceipt}.enable();
                                    }" />
                           </Listeners>
                        </ext:CheckboxSelectionModel>
                    </SelectionModel>
                    <TopBar>
                        <ext:Toolbar runat="server">
                            <Items>
                                <ext:Button ID="btnChooseReceipt" runat="server" Text="Chốt sổ" Icon="Accept" ToolTip="Chốt sổ">
                                    <DirectEvents>
                                        <Click OnEvent="btnChooseReceipt_Click">
                                            <EventMask ShowMask="true" Msg="Đang tải..." />
                                        </Click>
                                    </DirectEvents>
                                </ext:Button>
                                <ext:ToolbarSeparator />
                                <ext:DateField ID="txtDateBeginReceiptFillter" EmptyText="Từ ngày" runat="server" MarginSpec="0 8 0 0"/>
                                <ext:DateField ID="txtDateEndReceiptFillter" EmptyText="Đến ngày" runat="server" MarginSpec="0 5 0 0"/>
                                <ext:Button ID="btnReportFillterReport" runat="server" Text="Lọc" Icon="ApplicationGo" ToolTip="Chọn lọc theo ngày đặt hàng">
                                    <DirectEvents>
                                        <Click OnEvent="btnReportFillterReport_Click">
                                            <EventMask ShowMask="true" Msg="Đang tải..." />
                                        </Click>
                                    </DirectEvents>
                                </ext:Button>
                            </Items>
                        </ext:Toolbar>
                    </TopBar>
                    <DockedItems>
                        <ext:Toolbar runat="server" Dock="Bottom" AnchorHorizontal="100%">
                            <Items>
                                <ext:PagingToolbar runat="server" StoreID="StoreReportReceiptOrder" BeforePageText="Trang" AfterPageText="của {0}" LastText="Cuối" NextText="Kế tiếp" PrevText="Trở lại" FirstText="Đầu" RefreshText="Làm tươi" DisplayInfo="true" DisplayMsg="Trang {0} - {1} của {2}" />
                            </Items>
                        </ext:Toolbar>
                    </DockedItems>
                </ext:GridPanel>
            </Items>
        </ext:Window>
    </Content>
</ext:Panel>